package com.um2.mauction.java;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.DynaActionForm;

public class FrmPlaceBidBean extends DynaActionForm {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public ActionErrors validate(ActionMapping arg0, HttpServletRequest arg1) {

		// String oldBid = (String) this.get("txtOldBid");
		// String newBid = (String) this.get("txtNewBid");

		ActionErrors errors = new ActionErrors();

		if (get("txtNewBid") == null
				|| ((String) get("txtNewBid")).trim().equals("")) {
			errors.add("newBidNull", new ActionMessage("placebid.newBid.null"));
		} else

		if (get("txtOldBid") == null
				|| ((String) get("txtOldBid")).trim().equals("")) {
			errors.add("newBidNull", new ActionMessage("placebid.newBid.null"));
		} else

		if (Float.parseFloat((String) get("txtNewBid")) < Float
				.parseFloat((String) get("txtOldBid"))) {
			errors.add("newBidTooSmall", new ActionMessage(
					"placebid.newBid.toosmall"));
		}

		/*
		 * if (newBid == null || newBid.trim().equals("")) {
		 * errors.add("auctionDateVide", new ActionMessage(
		 * "AjoutProduit.particulier.auctionDate.vide")); } // Vérifier type
		 * flottant oldBid / newBid // [..]
		 * 
		 * if (Float.parseFloat(newBid) < Float.parseFloat(oldBid) ) {
		 * errors.add("auctionDurationVide", new ActionMessage(
		 * "AjoutProduit.particulier.auctionDuration.vide")); }
		 * 
		 * 
		 * if (Float.parseFloat(newBid) == Float.parseFloat(oldBid)) {
		 * errors.add("auctionDurationVide", new ActionMessage(
		 * "AjoutProduit.particulier.auctionDuration.vide")); }
		 */
		return errors;
	}

}
